package gui;

import gui.Machine.MachineListFrame;
import gui.RepairType.RepairTypeListFrame;
import gui.Reparation.ReparationCUDialog;
import gui.Reparation.ReparationListFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import javax.swing.JButton;
import javax.swing.JFrame;

public class MainFrame extends JFrame {

	protected static SimpleDateFormat m_frm;
	private JButton btnNewRep, btnReparations, btnRepairTypes, btnMachines;
	private ReparationListFrame reparationListFrame;
	private RepairTypeListFrame repairTypeListFrame;
	private MachineListFrame machineListFrame;

	// private static MainFrame instance = new MainFrame();
	//
	// public static MainFrame getInstance() {
	// return instance;
	// }
	
	public MainFrame() {
		setTitle("Koopy");
		setBounds(340, 140, 300, 300);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(null);

		m_frm = new SimpleDateFormat("<hh:mm:ss a> EE MMM dd, yyyy");

		getButtons();
	}

	private void getButtons() {

		btnNewRep = new JButton("Create new Rep");
		btnNewRep.setBounds(40, 00, 150, 25);
		btnNewRep.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				ReparationCUDialog repC = new ReparationCUDialog(
						MainFrame.this, "Create a Repararion");
				// Conference conference =
				// (Conference)listofConferences.getSelectedValue();
				// repC.setConference(conference);
				repC.setVisible(true);

			}
		});
		add(btnNewRep);

		btnReparations = new JButton("Reparations");
		btnReparations.setBounds(40, 40, 100, 25);
		btnReparations.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (e.getSource() == btnReparations) {
					if (reparationListFrame == null)
						reparationListFrame = new ReparationListFrame();
					reparationListFrame.fillListReparation();
					reparationListFrame.setVisible(true);
				}

			}
		});
		add(btnReparations);

		btnRepairTypes = new JButton("RepairTypes");
		btnRepairTypes.setBounds(40, 80, 100, 25);
		btnRepairTypes.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (e.getSource() == btnRepairTypes) {
					if (repairTypeListFrame == null)
						repairTypeListFrame = new RepairTypeListFrame();
					repairTypeListFrame.fillListRepairType();
					repairTypeListFrame.setVisible(true);
				}

			}
		});
		add(btnRepairTypes);

		btnMachines = new JButton("Machines");
		//btnMachines.setColor(Color.blue);
		btnMachines.setBounds(40, 120, 100, 25);
		btnMachines.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (e.getSource() == btnMachines) {
					if (machineListFrame == null)
						machineListFrame = new MachineListFrame();
					machineListFrame.fillListMachine();
					machineListFrame.setVisible(true);
				}

			}
		});
		add(btnMachines);
	}

	/**
	 * Gets the SimpleDateFormat.
	 * 
	 * @return to the SimpleDateFormat.
	 * 
	 * @author Csaba Tarkanyi
	 */
	public static SimpleDateFormat getSimpleDateFormat() {
		return m_frm;
	}
}
